#!/bin/bash

. /etc/rc.d/init.d/functions

RETVAL=0

start() {
	echo -n "Starting myvnc: "
	daemon --user=%USER% /usr/local/bin/myvnc.sh
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/myvnc
}

stop() {
	echo -n "Stopping myvnc: "
	killproc /usr/local/bin/myvnc.sh -HUP
	RETVAL=$?
	killproc /usr/bin/Xvfb -HUP
	[ $RETVAL -eq 0 ] && RETVAL=$?
	killproc /usr/bin/x11vnc -HUP
	[ $RETVAL -eq 0 ] && RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/myvnc
}

restart() {
	stop
	start
}

case "$1" in
  start)
	start
	;;
  stop) 
	stop
	;;
  restart|force-reload|reload)
	restart
	;;
  condrestart)
	[ -f /var/lock/subsys/myvnc ] && restart
	;;
  status)
	status /usr/local/bin/myvnc.sh
	RETVAL=$?
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
	exit 1
esac

exit $RETVAL
